﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Layer : ILayer
    {
        public void Add(Layer item)
        {
            CakeEntities db = new CakeEntities();
            db.Layer.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Layer.Remove(db.Layer.Find(id));
            db.SaveChanges();
        }

        public Layer FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.Layer.Find(id);
        }

        public List<Layer> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.Layer.ToList();
        }

        public void Updata(int id, Layer item)
        {
            CakeEntities db = new CakeEntities();
            var data=db.Layer.Find(id);
            if (data != null)
            {
                data.LayerName = item.LayerName;
                db.SaveChanges();
            }
        }
    }
}
